#!/usr/bin/env bash

goimports="goimports"

find_files() {
  find . -not \( \
      \( \
        -wholename './output' \
        -o -wholename './_output' \
        -o -wholename './_gopath' \
        -o -wholename './release' \
        -o -wholename './target' \
        -o -wholename '*/third_party/*' \
        -o -wholename '*/vendor/*' \
      \) -prune \
    \) -name '*.go'
}

diff=$(find_files | xargs ${goimports} -d -e 2>&1)
if [[ -n "${diff}" ]]; then
  echo "${diff}"
  exit 1
fi
